function uploadResponse(){
	var iframeId = document.getElementById("bat_iframehide");
	var content;
	 if (iframeId.contentDocument) {
        content = iframeId.contentDocument.body.innerHTML;
    } else if (iframeId.contentWindow) {
        content = iframeId.contentWindow.document.body.innerHTML;
    } else if (iframeId.document) {
        content = iframeId.document.body.innerHTML;
    }
 	if(content.indexOf('OK')==0){
 		Ext.MessageBox.hide();
 	}else{
 		if(!content.trim()=="")
 			Ext.MessageBox.alert('上传文件失败',content);
 	}
}
Ext.util.Format.comboRenderer = function(combo){
    return function(value){
        var record = combo.findRecord(combo.valueField, value);
        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
    };
};


/*Ext.grid.CheckColumn = function(config){
    Ext.apply(this, config);
    if(!this.id){
        this.id = Ext.id();
    }
    this.renderer = this.renderer.createDelegate(this);
};

Ext.grid.CheckColumn.prototype ={
    init : function(grid){
        this.grid = grid;
        this.grid.on('render', function(){
            var view = this.grid.getView();
            view.mainBody.on('mousedown', this.onMouseDown, this);
        }, this);
    },

    onMouseDown : function(e, t){
        if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
            e.stopEvent();
            var index = this.grid.getView().findRowIndex(t);
            var record = this.grid.store.getAt(index);
            var val = record.data[this.dataIndex];
            if(val=='Y')
            	val='N';
            else
            	val='Y';
            var editEvent = {
            	grid: this.grid,
            	record: this.grid.store.getAt(index),
            	field: this.dataIndex,
            	value: val,
            	originalValue: record.data[this.dataIndex],
            	row: index,
            	column: this.grid.getColumnModel().findColumnIndex(this.dataIndex)
            };
            record.set(this.dataIndex, editEvent.value);
            this.grid.fireEvent('afteredit',editEvent);
        }
    },

    renderer : function(v, p, record){
        p.css += ' x-grid3-check-col-td'; 
        var by = (v=='Y');
        return '<div class="x-grid3-check-col'+(by?'-on':'')+' x-grid3-cc-'+this.id+'"></div>';
    }
};
*/
/*------------------------------------------------------------*/
//Ext.ns('Ext.ux','Ext.ux.form');
Ext.ns('Ext.ux.grid');

Ext.define('Ext.ux.grid.CheckColumn', {
	extend:'Ext.grid.Column',

    /**
     * @private
     * Process and refire events routed from the GridView's processEvent method.
     */
    processEvent : function(name, e, grid, rowIndex, colIndex){
        if (name == 'mousedown') {
            var record = grid.store.getAt(rowIndex);
            record.set(this.dataIndex, !record.data[this.dataIndex]);
            return false; // Cancel row selection.
        } else {
            return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
        }
    },

    renderer : function(v, p, record){
        p.css += ' x-grid3-check-col-td'; 
        return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
    },

    // Deprecate use as a plugin. Remove in 4.0
    init: Ext.emptyFn
});

Ext.define('Ext.form.TreeCombo', {
	extend:'Ext.form.TriggerField',
    triggerClass: 'x-form-tree-trigger',

    getPathText:function(node){
    	return node.getPath('text',this.pathSpliter).substring(6);
    },
    initComponent : function(){
    	//c4w
 		this.id=Ext.id();
        this.readOnly = false;
		this.isExpanded = false;
		//c4w
		if(!this.root)
			this.root={
				text:"Root", 
				allowDrag:false,
				allowDrop:false
			};
			//this.root = new Ext.tree.AsyncTreeNode({  });
		if (!this.sepperator) {
                this.sepperator=','
        }
		if (!this.pathSpliter) {
                this.pathSpliter='#'
        }
		
		if (!Ext.isDefined(this.singleCheck)) {
            this.singleCheck=false;
        } 
        
        Ext.form.TreeCombo.superclass.initComponent.call(this);
        this.on('show',function() {
			this.setRawValue('');
			this.getTree();
			
			if (this.treePanel.loader.isLoading()) {
				this.treePanel.loader.on('load',function(c,n) {
					//c4w
					//n.expandChildNodes(true);
					if (this.setValueToTree()) this.getValueFromTree();
				},this);
			} else {
				if (this.setValueToTree()) this.getValueFromTree();
			}
		});
    },
	
	onTriggerClick: function() {
		if (this.isExpanded) {
			this.collapse();
		} else {
			this.expand();
		}
    } ,
	
	// was called combobox was collapse
    collapse: function() {
		this.isExpanded=false;
		this.getTree().hide();
        if (this.resizer)this.resizer.resizeTo(this.treeWidth, this.treeHeight);
		this.getValueFromTree();
    },
	
	// was called combobox was expand
	expand: function () {
        this.isExpanded=true;
		this.getTree().show();
		var el = this.getTree().getEl();
        el.alignTo(this.getEl().wrap(), 'tl-bl?');

		this.setValueToTree();
	},
	setValue: function (v) {
		this.value=v;
		this.setValueToTree();
	},
	
    getValue: function() {
        if (!this.value) { 
			return '';
		} else {
			return this.value;
		}
    },
	setValueToTree: function () {
		//c4w
		this.setRawValue(this.value);
		if(this.singleSelect)
			return false;
		// check for tree ist exist
		if (!this.treePanel){
			//c4w
			this.getTree();
			//return false;
		}

		// split this.value to array with sepperate value-elements
		var arrVal=new Array();
		try {
			arrVal = this.value.split(this.sepperator);
		} catch (e) {};
		
		// find root-element of treepanel, and expand all childs
		var node=this.treePanel.getRootNode();
		//c4w
		node.expandChildren(true);
		
		// search all tree-children and check it, when value in this.value
		node.cascadeBy(function (n) {
			var nodeCompareVal='';
			var nodeCheckState=false;  // default the note will be unchecked
			
			if (n.value) {
				// in node-element a value-property was used
				nodeCompareVal=Ext.util.Format.trim(n.value);
			} else {
				// in node-element can't find a value-property, for compare with this.value will be use node-element.text
				//c4w 
				//nodeCompareVal=String.trim(n.attributes.text);
				nodeCompareVal=Ext.util.Format.trim(this.getPathText(n));
			}
			
			Ext.each(arrVal,function(arrVal_Item) {
				if (Ext.util.Format.trim(arrVal_Item) == nodeCompareVal) {
					// set variable "nodeCheckState" to check node
					nodeCheckState=true;
				}
			},this);			
			// when state (of node) is other as variable "nodeCheckState", then set new value to node!
			if(n.get('checked')!=nodeCheckState){
				n.set('checked',nodeCheckState);
				n.fireEvent('checkchange', n, nodeCheckState);  
			}
			//if (n.getUI().isChecked()!=nodeCheckState) n.getUI().toggleCheck(nodeCheckState);			
		},this);		
		return true;
	},
	
	
	
	getValueFromTree: function () {
		if(!this.singleSelect){		
			this.ArrVal= new Array();
			this.ArrDesc= new Array();
	
			Ext.each(this.treePanel.getChecked(),function(item) {
				if (!item.get('value')) {
					//c4w
					this.ArrVal.push(this.getPathText(item));
				} else {
					this.ArrVal.push(item.value);
				}
				this.ArrDesc.push(this.getPathText(item));
			},this);
	
	
			this.value=this.ArrVal.join(this.sepperator);
			this.valueText=this.ArrDesc.join(this.sepperator);
		}else{
			
		}
		this.setRawValue(this.valueText);
		this.setValue(this.value);
		this.fireEvent("change", this, this.value);
	},
	
	validateBlur : function(){
        return !this.treePanel || !this.treePanel.isVisible();
    },

	/*
	 * following functions are using by treePanel
	 */
	
    getTree: function() {
        if (!this.treePanel) {
            if (!this.treeWidth) {
                this.treeWidth = Math.max(200, this.width || 200);
            }
            if (!this.treeHeight) {
                this.treeHeight = 200;
            }
            this.treePanel = new Ext.tree.TreePanel({
                renderTo: Ext.getBody(),
                pathSeparator :'#',
                id:Ext.id(),
                store: this.store ,
                root: this.root,
                rootVisible: false,
                floating: true,
                autoScroll: true,
                minWidth: 200,
                minHeight: 200,
                width: this.treeWidth,
                height: this.treeHeight,
                listeners: {
                    hide: this.onTreeHide,
                    show: this.onTreeShow,
                    select: this.onTreeNodeClick,
					checkchange: this.onTreeCheckChange,
                    expand: this.onExpandOrCollapseNode,
                    collapse: this.onExpandOrCollapseNode,
                    resize: this.onTreeResize,
                    scope: this
                }
            });
            this.treePanel.show();
            this.treePanel.hide();
            //this.relayEvents(this.treePanel.loader, ['beforeload', 'load', 'loadexception']);
            if(this.resizable){
                this.resizer = new Ext.Resizable(this.treePanel.getEl(),  {
                   pinned:true, handles:'se'
                });
                this.mon(this.resizer, 'resize', function(r, w, h){
                    this.treePanel.setSize(w, h);
                }, this);
            }
        }
        return this.treePanel;
    },

    onExpandOrCollapseNode: function() {
        if (!this.maxHeight || this.resizable)
            return;  // -----------------------------> RETURN
        var treeEl = this.treePanel.getTreeEl();
        var heightPadding = treeEl.getHeight() - treeEl.dom.clientHeight;
        var ulEl = treeEl.child('ul');  // Get the underlying tree element
        var heightRequired = ulEl.getHeight() + heightPadding;
        if (heightRequired > this.maxHeight)
            heightRequired = this.maxHeight;
        this.treePanel.setHeight(heightRequired);
    },

    onTreeResize: function() {
        if (this.treePanel)
            this.treePanel.getEl().alignTo(this.getEl().wrap(), 'tl-bl?');
    },

    onTreeShow: function() {
        Ext.getDoc().on('mousewheel', this.collapseIf, this);
        Ext.getDoc().on('mousedown', this.collapseIf, this);
    },

    onTreeHide: function() {
        Ext.getDoc().un('mousewheel', this.collapseIf, this);
        Ext.getDoc().un('mousedown', this.collapseIf, this);
    },

    collapseIf : function(e){
        if(!e.within(this.wrap) && !e.within(this.getTree().getEl())){
            this.collapse();
        }
    },

    onTreeNodeClick: function(tree, node) {
    	if(this.singleSelect){
    		if(node.get('value')){
    			this.value=node.get('value');
    		}else{
    			this.value=this.getPathText(node);
    		}
	        this.valueText =this.getPathText(node);
	        this.collapse();
    	}
   },
	
	onTreeCheckChange:function (node,value) {
		if (this.singleCheck) {
			// temporary disable event-listeners on treePanel-object 
			this.treePanel.suspendEvents(false);

			// disable all tree-checkboxes, there checked at the moment			
			Ext.each(this.treePanel.getChecked(),function(arrVal) { 
				arrVal.getUI().toggleCheck(false);
			} );
			
			// re-check the selected node on treePanel-object
			node.getUI().toggleCheck(true);
			
			// activate event-listeners on treePanel-object
			this.treePanel.resumeEvents();
		}
	},
	
	getRendererFunction: function (value) {
		var out=new Array();
		
		//console.info(value);
		//console.debug(this.getEditor().field.loader);
		if (Ext.util.Format.trim(value)!="") {
			var TreePanel = this.getEditor().field.getTree();
			var Sepperator = this.getEditor().field.sepperator;
			
				
			// split this.value to array with sepperate value-elements
			var arrVal=new Array();
			try {
				arrVal = value.split(Sepperator);
			} catch (e) {};
				
			TreePanel.expandAll();			
			TreePanel.getRootNode().cascadeBy(function (n) {
				Ext.each(arrVal,function(arrVal_Item) {
					if (Ext.util.Format.trim(arrVal_Item) == n.attributes.value) {
						out.push(n.attributes.text);
					}
				},this);
			});
					
			//console.debug("OUT",out);		
			//console.debug("TreePanel",TreePanel);
		}
		
		if (out.length!=0) {
			return out.join(Sepperator + ' ');	
		} else {
			return value;
		}
		
	}
	
});


/**
 * Plugin for adding a close context menu to tabs. Note that the menu respects
 * the closable configuration on the tab. As such, commands like remove others
 * and remove all will not remove items that are not closable.
 */
Ext.define('Ext.ux.TabCloseMenu', {
    alias: 'plugin.tabclosemenu',

    mixins: {
        observable: 'Ext.util.Observable'
    },

    /**
     * @cfg {String} closeTabText
     * The text for closing the current tab.
     */
    closeTabText: '关闭本页',

    /**
     * @cfg {Boolean} showCloseOthers
     * Indicates whether to show the 'Close Others' option.
     */
    showCloseOthers: true,

    /**
     * @cfg {String} closeOthersTabsText
     * The text for closing all tabs except the current one.
     */
    closeOthersTabsText: '关闭其他页',

    /**
     * @cfg {Boolean} showCloseAll
     * Indicates whether to show the 'Close All' option.
     */
    showCloseAll: true,

    /**
     * @cfg {String} closeAllTabsText
     * The text for closing all tabs.
     */
    closeAllTabsText: '关闭全部',

    /**
     * @cfg {Array} extraItemsHead
     * An array of additional context menu items to add to the front of the context menu.
     */
    extraItemsHead: null,

    /**
     * @cfg {Array} extraItemsTail
     * An array of additional context menu items to add to the end of the context menu.
     */
    extraItemsTail: null,

    //public
    constructor: function (config) {
        this.addEvents(
            'aftermenu',
            'beforemenu');

        this.mixins.observable.constructor.call(this, config);
    },

    init : function(tabpanel){
        this.tabPanel = tabpanel;
        this.tabBar = tabpanel.down("tabbar");

        this.mon(this.tabPanel, {
            scope: this,
            afterlayout: this.onAfterLayout,
            single: true
        });
    },

    onAfterLayout: function() {
        this.mon(this.tabBar.el, {
            scope: this,
            contextmenu: this.onContextMenu,
            delegate: '.x-tab'
        });
    },

    onBeforeDestroy : function(){
        Ext.destroy(this.menu);
        this.callParent(arguments);
    },

    // private
    onContextMenu : function(event, target){
        var me = this,
            menu = me.createMenu(),
            disableAll = true,
            disableOthers = true,
            tab = me.tabBar.getChildByElement(target),
            index = me.tabBar.items.indexOf(tab);

        me.item = me.tabPanel.getComponent(index);
        menu.child('*[text="' + me.closeTabText + '"]').setDisabled(!me.item.closable);

        if (me.showCloseAll || me.showCloseOthers) {
            me.tabPanel.items.each(function(item) {
                if (item.closable) {
                    disableAll = false;
                    if (item != me.item) {
                        disableOthers = false;
                        return false;
                    }
                }
                return true;
            });

            if (me.showCloseAll) {
                menu.child('*[text="' + me.closeAllTabsText + '"]').setDisabled(disableAll);
            }

            if (me.showCloseOthers) {
                menu.child('*[text="' + me.closeOthersTabsText + '"]').setDisabled(disableOthers);
            }
        }

        event.preventDefault();
        me.fireEvent('beforemenu', menu, me.item, me);

        menu.showAt(event.getXY());
    },

    createMenu : function() {
        var me = this;

        if (!me.menu) {
            var items = [{
                text: me.closeTabText,
                scope: me,
                handler: me.onClose
            }];

            if (me.showCloseAll || me.showCloseOthers) {
                items.push('-');
            }

            if (me.showCloseOthers) {
                items.push({
                    text: me.closeOthersTabsText,
                    scope: me,
                    handler: me.onCloseOthers
                });
            }

            if (me.showCloseAll) {
                items.push({
                    text: me.closeAllTabsText,
                    scope: me,
                    handler: me.onCloseAll
                });
            }

            if (me.extraItemsHead) {
                items = me.extraItemsHead.concat(items);
            }

            if (me.extraItemsTail) {
                items = items.concat(me.extraItemsTail);
            }

            me.menu = Ext.create('Ext.menu.Menu', {
                items: items,
                listeners: {
                    hide: me.onHideMenu,
                    scope: me
                }
            });
        }

        return me.menu;
    },

    onHideMenu: function () {
        var me = this;

        //me.item = null;
        me.fireEvent('aftermenu', me.menu, me);
    },

    onClose : function(){
        this.tabPanel.remove(this.item);
    },

    onCloseOthers : function(){
        this.doClose(true);
    },

    onCloseAll : function(){
        this.doClose(false);
    },

    doClose : function(excludeActive){
        var items = [];

        this.tabPanel.items.each(function(item){
            if(item.closable){
                if(!excludeActive || item != this.item){
                    items.push(item);
                }
            }
        }, this);

        Ext.each(items, function(item){
            this.tabPanel.remove(item);
        }, this);
    }
});


Ext.define('Ext.form.FileField', {
	extend :'Ext.form.field.Base', 
    setPlink:function(plink){
    	this.plink = plink;
    	this.elink.innerHTML = plink;
    },
    getValue : function(){
        return Ext.form.FileField.superclass.getValue.call(this)|| "";
    },
	setReadOnly:function( readOnly ){
		this.callParent(arguments);
		var eo = this.bodyEl.el;
		var tr=eo.query("tr",true)[0];
		if(readOnly){
			tr.cells[0].style.display="none";
			tr.cells[1].style.display="none";
		}else{
			tr.cells[0].style.display="";
			tr.cells[1].style.display="";
		}
	},
    setValue : function(val){
        Ext.form.FileField.superclass.setValue.call(this, val);
        this.fireEvent("change", this, val);
    },
    // private
    initComponent: function(){
        Ext.form.FileField.superclass.initComponent.call(this);
        
        this.addEvents(
            'uploaded',
            'fileselected'
        );
    },
    // private
    onRender : function(ct, position){
        var me = this,
            id = me.id,
            bodyEl;

        me.callParent(arguments);

        inputEl = me.bodyEl;
       // Ext.form.FileField.superclass.onRender.call(this, ct, position);
        var eo = me.bodyEl.el;

        eo.dom.innerHTML="<div><table><tr><td ><form action='"
        +Bat.WC+"servlet/fu' method='POST' enctype='multipart/form-data' target='bat_iframehide'>" +
       "</form></td><td></td><td></td></tr></table><div>";
       
    	var dh = Ext.DomHelper;
         var tr=eo.query("tr",true)[0];
        var fm=eo.query("form",true)[0];
		fm.encoding="multipart/form-data";
        
        var file=dh.append(fm,{tag: "input",type: "file",name:"file", cls:"x-btn-button"});
        this.file = file;
        Ext.get(file).on('change', function(){
            var v = this.file.value;
            this.setValue(v);
            this.fireEvent('fileselected', this, v);
        }, this);
        var btntd=tr.cells[1];
        var elink=tr.cells[2];
        me.elink = elink;
        if(this.plink){
	        var elink=tr.cells[2];
	        if(elink){
		        elink.innerHTML = this.plink;		        
	        }
        }
       // var me=this;
        var todayBtn = new Ext.Button({
        	renderTo :btntd, 
            text: "上传",
            //tooltip: "upload a file",
            handler:function(){
            	var total=240;
            	var cur=0;
            	var remoteTotal;
				var fpath=me.file.value;
				if(fpath!=""){
					var pos=fpath.lastIndexOf("\\");
					me.fname=fpath.substr(pos+1);
					me.fn=me.fname;
				}

		 		var req={map:{},"javaClass":"java.util.HashMap"};
		   	 	jsonrpc.BH.handle(function(data,ex){
		   			if(Bat.outputEx(ex,'获取任务号异常'))
		   				return;		   	 		
		   	 		var tid = data;
		   	 		//c4wtodo 121005 用户上传目录分离
		   	 		var pos=tid.indexOf('_',1);
		   	 		var uid = tid.substring(0,pos);
        			me.fn="_["+uid+"]"+tid+"_"+me.fname;
        			me.setValue(me.fn);
    				var oa=fm.action;
    				fm.action+="?tid="+tid;
    				Ext.MessageBox.show({ msg:'正在上传，请稍候...',title:'系统提示',
    					modal:false,wait:true,closable:false});
    				fm.submit();
    				fm.action=oa;					
		   	 	 },'N',req,"TaskHandle");  		
        		//Bat.showProgress(null,true);	
            },
            scope: me
        });
    }
        
});

Ext.define('Ext.form.TA', {
   extend: 'Ext.form.TextArea',
   config: {
	enableKeyEvents:true,
  	listeners:{
	'blur':function(fd,e){
		var me=this;
		me.hideMenu();
		me.bStep=false;
		if(me.timer){
			clearTimeout(me.timer);
		}
	},
	'focus':function(fd,e){
		var me = this;
		me.bStep = true;
		me.stepCheck();
	},
  	 'specialkey': function(field, e){
  	 	this.onKey(e);
     }
	 }
	},
	 setSelectRange : function(start, end ){
	 	var textarea=this.inputEl.dom;  
         if ( typeof textarea.createTextRange != 'undefined' )// IE
          {
              var range = textarea.createTextRange();
               // 先把相对起点移动到0处
              range.moveStart( "character", 0)
              range.moveEnd( "character", 0);
              range.collapse( true); // 移动插入光标到start处
     
              range.moveEnd( "character", end);
              range.moveStart( "character", start);
     
              range.select();
          } // if
           else if ( typeof textarea.setSelectionRange != 'undefined' ){     
             　　 textarea.selectionStart=start;
             　　 textarea.selectionEnd = end;
         　} 
　　　},
	getSelectionStart:function() {
	  var node = this.inputEl.dom;
	  if (node.selectionStart) {
	    return node.selectionStart;
	  } else if (!document.selection) {
	    return 0;
	  }
	
		var range = document.selection.createRange();
		var range_textarea = document.body.createTextRange();
	    range_textarea .moveToElementText(node); 
	           //比较start point 
	   for ( var sel_start = 0; range_textarea .compareEndPoints('StartToStart' , range) < 0; sel_start++)
	       range_textarea.moveStart( 'character', 1);
	 
	  return sel_start;
	},
	stepCheck:function(){
		var me=this;
		//var ta = me.inputEl.dom;  
		var pos = me.getSelectionStart();
		//console.log('stepCheck:pos:'+pos+' pos_start:'+me.pos_start);
		if(pos!=me.pos_start){
			me.showMenu(true);
			me.pos_start=pos;
		}
		if(me.bStep){
			//killTimer(me.timer);
			me.timer = setTimeout(function(){
				me.stepCheck();
			},300);
		}
	},
	filterBy:function(str){
		var me = this;
		this.mnu.getStore().filterBy(function(rd){
			if(me.func_filterBy){
				return me.func_filterBy(rd,str);
			}else return rd.get('pyh').indexOf(str)==0;
		},this);
	},
	showMenu:function(bfocus){
		var ta = this;
		var pos = ta.getSelectionStart();
		var txt = ta.getRawValue( ).substring(0,pos);
		var p0 = ta.getXY();
		//console.log(txt);
		
		var bHide=false;
		var key;
		var pos_at = txt.lastIndexOf('@');
		if(pos_at==-1){
			bHide=true;
		}else{
			key = txt.substring(pos_at+1);
			//不允许中间有空格
			if(key.indexOf(' ')!=-1)
				bHide=true;
		}
		if(bHide){
			ta.hideMenu();
			return;
		}
		var x = p0[0]+ta.getDivWidth(txt);
		var y = p0[1]+ta.getDivHeight(txt);
		//contactsDropDown.bindElement(ta.el);
		var mnu = this.mnu;
       	mnu.showAt([x,y]);
       	this.filterBy(key);
       	mnu.getSelectionModel().select(0,true,true);
       	if(bfocus)
       		this.focus();		
	},
	hideMenu:function(){
		this.mnu.hide();
	},
    constructor: function (config) {
    	config.width =config.width||400;
    	config.height =config.height||200;
        this.callParent(arguments); 
    },
	getDivHeight:function(text){
		this.heightDiv.setHTML(text.replace(/\n/g, '<br/>'));
		return this.heightDiv.getHeight() + 10;
	},
	getDivWidth:function(text){
       var h = this.getDivHeight('x');
       var olen = this.getDivHeight(text);
        if (h != olen) {
            for (var i = 0; i < text.length; ++i) {
                var s = text.substr(0, text.length - i);
                var len = this.getDivHeight(s);
                if (len != olen) {
                    text = text.substr(text.length - i);
                    break;
                }
            }
        }
        this.widthDiv.setHTML(text);
        return this.widthDiv.getWidth();
	},
	buildMenu:function(){
		var me=this;
		var hql="select id,name,namePyh from UUser";
		me.mnu=Ext.create('Ext.grid.Panel', {
			floating:true,
			//focusOnToFront:false,
			selModel: 'SINGLE',
		    store: me.ds,
		    hideHeaders :true,
		    columns: me.columns,
		    height: me.menuHeight||200,
		    width: me.menuWidth||400
		});	
		me.mnu.on("select",function(gd, record, item, index, e, eOpts ){
			me.onSelOk();
		});
	},
	insertText:function(val){  
        var ta = this.inputEl.dom;  
        var oriValue = this.getValue();  
        var pos_cursor = this.getSelectionStart();
        var txt1=oriValue.substring(0,pos_cursor);
        var pos_start,value,pos_end;
        if(val=='\r\n'){
        	value=val;
        	pos_start=pos_cursor-1;
        	//pos_end = pos_cursor+value.length-1;
        	pos_end = pos_start+value.length;
        }else{        	
        	pos_start= txt1.lastIndexOf('@');
        	var txt2 = oriValue.substring(pos_cursor);
        	var pos2=txt2.indexOf(' ');
        	if(pos2==-1)
        		pos2=txt2.indexOf('\r');
        	if(pos2!=-1){
        		pos_cursor+=pos2;
        		value=val;
        	}else{
        		value=val+' ';
        	}
        	pos_end = pos_start+value.length+2;
        }
        
		this.setValue(oriValue.substring(0,pos_start+1) + value + oriValue.substring(pos_cursor));  
		this.setSelectRange(pos_end,pos_end);
	}, 
	onSelOk:function(){
  	 	var sel = this.mnu.getSelectionModel();
  	 	var si = sel.getSelection();
  	 	if(!si || si.length==0)
  	 		return;
  	 	this.insertText(this.func_insert(si[0].data)||si[0].data['name']);
  	 	this.hideMenu();
	},
	
  	onKey: function(e){
  		//console.log('onKey');
  	 	if(!this.mnu.isVisible()){
  	 		if(e.getKey()==e.ENTER){
  	 			this.insertText('\r\n');
  	 		}
  	 		return;
  	 	}
        // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
        // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
  	 	var sel = this.mnu.getSelectionModel();
  	 	var si = sel.getSelection();
  	 	var pos = 0;
  	 	if(si && si.length>0){
  	 		pos = si[0].index;
  	 	}
 		var mnu = this.mnu;
 		var ds = mnu.getStore();
 		var selectedRecord = sel.getLastSelected();
		var recordIndex = ds.indexOf(selectedRecord);
		var nextRecord ;

 	 	switch(e.getKey()){
        case e.DOWN:
  	 		e.stopEvent();
			nextRecord = recordIndex + 1;
			if(nextRecord>=ds.getCount())
				nextRecord=0;
			sel.select(ds.getAt(nextRecord),true,true); 	 		
			break;
         case e.UP:
         	e.stopEvent();
			nextRecord = recordIndex - 1;
			if(nextRecord<0)
				nextRecord=ds.getCount()-1;
			sel.select(ds.getAt(nextRecord),true,true); 	 		
	       	break;
	     case e.ESC:
  	 		e.stopEvent();
	     	this.hideMenu();
	       	break;
	     case e.ENTER:
  	 		e.stopEvent();
	     	this.onSelOk();
	       	break;
       }
	   //this.focus();
    },
	
	
  buildKey:function(){
    this.keyNav = new Ext.KeyNav(this.inputEl, {
        "enter": function(e) {
        	console.log('enter');
        	this.onKey(e);
        },
        "esc": function(e) {
        	console.log('esc');
        	this.onKey(e);
        },
        "tab": function(e) {
        	console.log('tab');
        	this.onKey(e);
        },
        scope: this
    });
  },
    onRender: function () {
        this.callParent();
		this.heightDiv = Ext.DomHelper.append(document.body,{tag:'div',id:'height_div',style:'visibility:hidden;position:absolute;z-index:10000;top:0px;left:3000px;word-break:break-all;word-wrap:break-word'},true);
		this.heightDiv.setWidth(this.getWidth());
		this.heightDiv.setStyle('font-size',this.inputEl.getStyle('font-size'));
		this.widthDiv = Ext.DomHelper.append(document.body,{tag:'div',id:'width_div',style:'visibility:hidden;position:absolute;z-index:10000;top:0px;left:3000px;'},true);
		this.widthDiv.setHeight(this.getHeight());
		this.widthDiv.setStyle('font-size',this.inputEl.getStyle('font-size'));  	
		
		this.buildMenu();
		this.buildKey();
   }
});